//
// Created by Snow on 2023/3/14.
//
#include<cstdio>
#include<cstdlib>
typedef int ElemType;
typedef struct LNode
{
    ElemType data;
    struct LNode *next;
}LinkNode;
void InitQueue(LinkNode *&rear)
{
    rear=nullptr;
}
void enQueue(LinkNode *&rear,ElemType e)
{
    LinkNode *p;
    p=(LinkNode *)malloc(sizeof(LinkNode));
    p->data=e;
    if(rear==nullptr)
    {
        p->next=p;
        rear=p;
    }
    else
    {
        p->next=rear->next;
        rear->next=p;
        rear=p;
    }
}
bool deQueue(LinkNode *&rear,ElemType &e)
{
    LinkNode *t;
    if(rear==nullptr)
        return false;
    else if(rear->next==rear)
    {
        e=rear->data;
        free(rear);
        rear=nullptr;
    }
    else
    {
        t=rear->next;
        e=t->data;
        rear->next=t->next;
        free(t);
    }
    return true;
}
bool QueueEmpty(LinkNode *&rear)
{
    return(rear==nullptr);
}
bool DestroyQueue(LinkNode *&rear)
{
    if(rear==nullptr)
        return false;
    LinkNode *pre=rear->next,*p=pre->next;
    while(p!=rear)
    {
        free(pre);
        pre=p;
        p=p->next;
    }
    free(pre);
    free(rear);
    return true;
}
int main()
{
    ElemType e,arr[]={1,2,3,4,5,6,7,'\0'};
    int i;
    LinkNode *rear;
    InitQueue(rear);
    if(QueueEmpty(rear))printf("Yes\n");
    for(i=0;arr[i]!='\0';i++)
        enQueue(rear,arr[i]);
    while(deQueue(rear,e))printf("%d ",e);
    DestroyQueue(rear);
    return 0;
}